package servlet;

import entity.Orgnazition;
import service.OrgnazitionService;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

@WebServlet(urlPatterns = "/AddServlet")
public class AddServlet extends HttpServlet {
    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        request.setCharacterEncoding("utf-8");
        response.setContentType("text/html;charset=utf-8");
        OrgnazitionService os = new OrgnazitionService();
        Orgnazition orgnazition = new Orgnazition(request.getParameter("name")
        ,request.getParameter("principalName")
        ,request.getParameter("createDate"));
        int result=os.add(orgnazition);
        if (result>0) {
            request.getRequestDispatcher("ListServlet").forward(request,response);
        }
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        doGet(req, resp);
    }
}
